home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / T U R B O Language / Turbo C v3.0 / TC3SETUP.EXE / BIN / TIMEIT.BAK < prev    next >
Text File  |  1994-04-10  |  1KB  |  67 lines

  1. #include <process.h>
  2. #include <iostream.h>
  3. #include <errno.h>
  4. #include <time.h>
  5. #include <stdio.h>
  6.  
  7. int main(int argc,char *argv[])
  8. {
  9. clock_t start,end;
  10. FILE *fp;
  11. int j;
  12. char bb = 'f';
  13. float var;
  14. char aa[45]="The time that complies the program is : ";
  15.  
  16. cout << "Command line arguments:\n\n";
  17. for (int i = 0; i < argc; ++i)
  18. {
  19.    cout << "Argument [" << i << "] : " << argv[i] << '\n';
  20. }
  21.    cout << "Measuring the time that needs to comply program ["
  22.     << argv[i-1] << ".cpp" << ']' << "\n\n";
  23.  
  24.  
  25. for(j=0;j<argc;++j)
  26. {
  27.    if((argv[j][0]=='-') && (argv[j][1]=='o'))
  28.    {
  29.       fp=fopen(argv[j+1],"w");
  30.       bb = 't';
  31.    }
  32.    if((argv[j][0]=='b') && (argv[j][1]=='c') && (argv[j][2]=='c'))
  33.       argv=argv+j;
  34. }
  35.  
  36.  
  37. start = clock();
  38.  
  39. int result = spawnvp(P_WAIT,"bcc",argv);
  40.  
  41. end = clock();
  42. var = (end - start) / CLK_TCK;
  43.  
  44. if (bb == 't')
  45. {
  46.    fprintf(fp,"%s",aa);
  47.    fprintf(fp,"%8.3f",var);
  48.    fclose(fp);
  49. }
  50.  
  51. if ((result != -1) && (bb != 't'))
  52. {
  53.     cout << "The time that complies the program is : "
  54.      << var << " second(s)" << '\n';
  55. }
  56.  
  57. if (result == -1)
  58. {
  59.    perror("execution error");
  60.  
  61. return result;
  62. }
  63.  
  64.  
  65.  
  66.